import { BasicColumn } from '@/components/Table';
import { FormSchema } from '@/components/Table';
import { render } from '/@/utils/common/renderUtils';
//列表数据
export const columns: BasicColumn[] = [
  {
    title: '关键字名称',
    align: 'center',
    dataIndex: 'keywordName',
  },
  {
    title: '关键字描述',
    align: 'center',
    dataIndex: 'keywordDesc',
  },
  {
    title: '子项目',
    align: 'center',
    dataIndex: 'subProjectName',
  },
];
//查询数据
export const searchFormSchema: FormSchema[] = [
  {
    label: '关键字名称',
    field: 'keywordName',
    component: 'Input',
  },
  {
    label: '子项目名称',
    field: 'subProject',
    component: 'JSelectDept',
    componentProps: ({ formActionType, formModel }) => {
      return {
        sync: false,
        checkStrictly: true,
        multiple: false,
        defaultExpandLevel: 2,
        onSelect: (options, values) => {
          const { updateSchema } = formActionType;
          //所属部门修改后更新负责部门下拉框数据
          updateSchema([
            {
              field: 'departIds',
              componentProps: { options },
            },
          ]);
          //update-begin---author:wangshuai---date:2024-05-11---for:【issues/1222】用户编辑界面“所属部门”与“负责部门”联动出错整---
          if(!values){
            formModel.departIds = [];
            return;
          }
          //update-end---author:wangshuai---date:2024-05-11---for:【issues/1222】用户编辑界面“所属部门”与“负责部门”联动出错整---
          //所属部门修改后更新负责部门数据
          formModel.departIds && (formModel.departIds = formModel.departIds.filter((item) => values.value.indexOf(item) > -1));
        },
      };
    },
  },
];
//表单数据
export const formSchema: FormSchema[] = [
  {
    label: '关键字名称',
    field: 'keywordName',
    component: 'Input',
    dynamicRules: ({ model, schema }) => {
      return [{ required: true, message: '请输入关键字名称!' }];
    },
  },
  {
    label: '关键字描述',
    field: 'keywordDesc',
    component: 'Input',
    dynamicRules: ({ model, schema }) => {
      return [{ required: true, message: '请输入关键字描述!' }];
    },
  },
  {
    label: '子项目',
    field: 'subProject',
    component: 'JSelectDept',
    componentProps: ({ formActionType, formModel }) => {
      return {
        sync: false,
        checkStrictly: true,
        multiple: false,
        defaultExpandLevel: 2,
        onSelect: (options, values) => {
          const { updateSchema } = formActionType;
          //所属部门修改后更新负责部门下拉框数据
          updateSchema([
            {
              field: 'departIds',
              componentProps: { options },
            },
          ]);
          //update-begin---author:wangshuai---date:2024-05-11---for:【issues/1222】用户编辑界面“所属部门”与“负责部门”联动出错整---
          if(!values){
            formModel.departIds = [];
            return;
          }
          //update-end---author:wangshuai---date:2024-05-11---for:【issues/1222】用户编辑界面“所属部门”与“负责部门”联动出错整---
          //所属部门修改后更新负责部门数据
          formModel.departIds && (formModel.departIds = formModel.departIds.filter((item) => values.value.indexOf(item) > -1));
        },
      };
    },
  },
  // TODO 主键隐藏字段，目前写死为ID
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false,
  },
];

// 高级查询数据
export const superQuerySchema = {
  keywordName: { title: '关键字名称', order: 0, view: 'text', type: 'string' },
  keywordDesc: { title: '关键字描述', order: 1, view: 'text', type: 'string' },
  subProject: { title: '子项目', order: 2, view: 'text', type: 'string' },
};

/**
 * 流程表单调用这个方法获取formSchema
 * @param param
 */
export function getBpmFormSchema(_formData): FormSchema[] {
  // 默认和原始表单保持一致 如果流程中配置了权限数据，这里需要单独处理formSchema
  return formSchema;
}
